<template>
  <div class="total">
    <!-- 登录页面表单 -->
    <div class="right">
      <div class="title">
        <div class="logo">
          <img src="../../static/img/logo.jpg" class="img1" />
        </div>
        <div class="name">城镇便民医疗系统</div>
      </div>
      <div class="one">领先的互联网基层医疗服务商</div>
      <!-- <form>
          <input placeholder="手机号码" class="input"/><br/>
          <input placeholder="密码" class="input"/><br/>
          <button class="input">登录</button>
      </form>-->
      <el-form
        :model="ruleForm"
        status-icon
        :rules="rules"
        ref="ruleForm"
        class="demo-ruleForm form"
      >
        <el-form-item prop="phoneNum">
          <el-input type="text" v-model="ruleForm.phoneNum" autocomplete="off" placeholder="手机号码"></el-input>
        </el-form-item>
        <el-form-item prop="pass">
          <el-input type="password" v-model="ruleForm.pass" autocomplete="off" placeholder="密码"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="submitForm('ruleForm')" class="submit">登录</el-button>
          <!-- <el-button @click="resetForm('ruleForm')">重置</el-button> -->
        </el-form-item>
      </el-form>
     
    </div>
  </div>
</template>
<script>
import axios from 'axios';
export default {
  data() {
    var validatephoneNum = (rule, value, callback) => {
      if (value === '') {
        callback(new Error('请输入手机号码'));
      } else {
        if (this.ruleForm.checkPass !== '') {
          this.$refs.ruleForm.validateField('checkPass');
        }
        callback();
      }
    };
    var validatePass = (rule, value, callback) => {
      if (value === '') {
        callback(new Error('请输入密码'));
      } else {
        if (this.ruleForm.pass !== '') {
          this.$refs.ruleForm.validateField('checkPass');
        }
        callback();
      }
    };

    return {
      ruleForm: {
        pass: '',
        phoneNum: '',
      },
      rules: {
        phoneNum: [{ validator: validatephoneNum, trigger: 'blur' }],
        pass: [{ validator: validatePass, trigger: 'blur' }],
      },
    };
  },
  methods: {
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          axios
            .post('/api/login/login', {
              admin_name: this.ruleForm.phoneNum,
              admin_pwd: this.ruleForm.pass,
            })
            .then((r) => {
              console.log("登录信息",r);
              if (r.data.code === 200) {
                
                sessionStorage.setItem('token',r.data.idCard);
                sessionStorage.setItem("userInfo",window.JSON.stringify(r.data.adminMessage));

                this.$router.push({
                  path:'/home'
                });
              }
              console.log(r);
            });
        } else {
          console.log('error submit!!');
          return false;
        }
      });
    },
  },
};
</script>
<style scoped>
.three {
  display: flex;
  justify-content: space-between;
  margin-top: 30px;
  font-size: 15px;
}
.one {
  color: #9b9ba0;
  margin-top: 5px;
}
.two {
  margin-top: -20px;
}
.submit {
  width: 100%;
  height: 50px;
  background-color: #34aca2;
}
.img1 {
  width: 55px;
  height: 55px;
  border-radius: 50%;
}
.logo {
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 1;
}
.name {
  border-left: 1px solid gainsboro;
  height: 100%;
  display: flex;
  flex: 2;
  align-items: center;
  justify-content: center;
}
.title {
  width: 80%;
  height: 70px;
  margin: auto;
  font-size: 30px;
  margin-top: 10px;
  display: flex;
  align-items: center;
}
.form {
  width: 85%;
  margin: auto;
  font-size: 18px;
  padding: 25px;
}
.right {
  position: absolute;
  width: 22%;
  height: 333px ;
  background-color: white;
  left: 40%;
  top: 50px;
  padding: 30px;
  text-align: center;
}
.total {
  width: 100%;
  height: 600px;
  /* height: 100%; */
  background-color: #34aca2;
  margin-top: 60px;
  position: relative;
}
.el-input >>> .el-input__inner {
  height: 50px;
}
</style>